package com.cloud.cloudvideo.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.cloudvideo.entity.TreePojo;
import com.cloud.cloudvideo.entity.VideoCate;
import com.cloud.cloudvideo.mapper.VideoCateMapper;
import com.cloud.cloudvideo.service.VideoCateService;

@Service
public class VideoCateServiceImpl implements VideoCateService{

	
	@Autowired
	private VideoCateMapper cateMapper;
	
	
	@Override
	public List<VideoCate> list() {
		List<VideoCate> list = cateMapper.selectByExample(null);
		return list;
	}


	@Override
	public List<TreePojo> treelist() {
		List<TreePojo> list = cateMapper.findCateWithChild();
		TreePojo sp = new TreePojo();
		sp.setId(-1L);
		sp.setParentId(-1L);
		sp.setTitle("顶级菜单");
		sp.setChildren(list);
		List<TreePojo> l = new ArrayList<>();
		l.add(sp);
		return l;
	}


	@Override
	public void modify(VideoCate cate) {
		if(null == cate.getId())
			cateMapper.insertSelective(cate);
		else
			cateMapper.updateByPrimaryKeySelective(cate);
	}


	@Override
	public void del(Long id) {
		cateMapper.deleteByPrimaryKey(id);
	}


	@Override
	public Map<String, Object> cateInfo(Long id) {
		Map<String, Object> map = new HashMap<>();
		VideoCate cate = cateMapper.selectByPrimaryKey(id);
		map.put("cate", cate);
		VideoCate pcate = cateMapper.selectByPrimaryKey(cate.getCategorypid());
		map.put("pcate", pcate);
		return map;
	}

}
